package io.bloom.webspider;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Map;

public class Main
{

    public static void main(String[] args)
    {
        Spider
                .builder()
                .name("baidu.com")
                .thread(3)
                .downloader(new OkHttpDownloader())
                .startUrl("http://taobao.com")
                .matcher(SpiderLinkMatcher.of("http(s)?://(.*.)?taobao.com/(.*)"))
                .processors(new ArrayList<Processor>(){
                    {
                        add(new IndexProcessor());
                    }
                })
                .build()
                .start();
        ;
    }


    @Slf4j
    private static class IndexProcessor implements Processor{

        public void execute(SpiderResponse response, Map<String, Object> context) {
            System.out.println(response.getLinks());
            System.out.println(response.getData());
        }

        public int index() {
            return 1;
        }
    }

}
